package com.example.streams;

import com.example.lists.User;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author hej
 * @date 2025/4/21 16:40
 */
public class StreamOrder {
    public static void main(String[] args) {
        //给集合某字段添加序号
        List<User> users = new ArrayList<>();
        users.add(new User(1, "老王"));
        users.add(new User(2, "老李"));
        users.add(new User(3, "老张"));
        System.out.println(users);
        AtomicInteger atomicInteger = new AtomicInteger();
        users.forEach(user -> {
            user.setId(atomicInteger.incrementAndGet());
        });
        System.out.println(users);
    }
}
